package isssr.bean.entity;

import java.io.Serializable;
import java.lang.reflect.Field;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;

import isssr.bean.utility.HibernateUtility;

@Entity
public class User extends MetaEntity{

	/*
	@ManyToMany(
	        cascade = {CascadeType.PERSIST, CascadeType.MERGE},
	        mappedBy = "organizationalGoal",
	        targetEntity = OrganizationalGoal.class
	    )
	*/
	private Integer id;
	private String firstName;
	private String lastName;
	private String email;
	private String username;
	private String password;
	private Boolean logged;
	private Role role;
	
	protected Serializable getMetaID()
	{
		return this.id;
	}
	
	public User()
	{
		this.logged = new Boolean(false);
	}
	
	public Integer getId() {
		return id;
	}



	public void setId(Integer id) {
		this.id = id;
	}



	public String getFirstName() {
		return firstName;
	}



	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}



	public String getLastName() {
		return lastName;
	}



	public void setLastName(String lastName) {
		this.lastName = lastName;
	}



	public String getEmail() {
		return email;
	}



	public void setEmail(String email) {
		this.email = email;
	}



	public String getUsername() {
		return username;
	}



	public void setUsername(String username) {
		this.username = username;
	}



	public String getPassword() {
		return password;
	}



	public void setPassword(String password) {
		this.password = password;
	}



	public Boolean getLogged() {
		return logged;
	}

	public void setLogged(Boolean logged) {
		this.logged = logged;
	}

	public Role getRole() {
		return role;
	}



	public void setRole(Role role) {
		this.role = role;
	}

	public boolean equals(Object o)
	{
		if(o==null)
			return false;
		
		if(this == o) 
			return true;
		
		if(this.getClass() != o.getClass())
			return false;
		
		User otherUser = (User) o;
		Object thisValue ;
		Object otherValue ;
		
		try
		{
			for(Field f : this.getClass().getDeclaredFields())
			{
				thisValue = f.get(this);
				otherValue = f.get(otherUser);
				
				if(thisValue==null)
				{
					if(otherValue!=null)
						return false;
				}
				else if(!thisValue.equals(otherValue))
				{
					return false;
				}
			}
		}
		catch(IllegalArgumentException ex)
		{
			ex.printStackTrace();
			return false;
		}
		catch(IllegalAccessException ex)
		{
			ex.printStackTrace();
			return false;
		}
		
		return true;
	}

/*
	public void registra(){
		HibernateUtility.persist(this);
	}
	*/

}
